package org.test.connectDB.comm;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

public abstract class AbstraceDataBaseComm {

	public final static String dburl = "dburl";
	public final static String userName = "userName";
	public final static String password = "password";

	protected Properties dataBaseProperties;
	protected Connection conn = null;
	protected Statement stmt = null;

	public Properties getDataBaseProperties() {
		return dataBaseProperties;
	}

	public void setDataBaseProperties(Properties dataBaseProperties) {
		this.dataBaseProperties = dataBaseProperties;
	}

	public Connection getConn() {
		return conn;
	}

	public void setConn(Connection conn) {
		this.conn = conn;
	}

	public Statement getStmt() {
		return stmt;
	}

	public void setStmt(Statement stmt) {
		this.stmt = stmt;
	}
	
	public  static List convertList(ResultSet rs) throws SQLException {
		List list = new ArrayList();
		ResultSetMetaData md = rs.getMetaData();
		int columnCount = md.getColumnCount();
		// Map rowData;
		while (rs.next()) {
			// rowData = new HashMap(columnCount);
			Map rowData = new HashMap();
			for (int i = 1; i <= columnCount; i++) {
				rowData.put(md.getColumnName(i), rs.getObject(i));
			}
			list.add(rowData);
		}
		return list;
	}

}
